﻿//=============================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：孙德响
// 日 期：2011-11-23
// 描 述: 心得点评编辑界面2
//
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2011/11/23    孙德响           
//=============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.TR.Bussiness;
using ZX.EHR.Library;
using ZX.TR.Library;


namespace ZX.WebApp.TR
{
    /// <summary>
    /// 心得点评编辑界面2
    /// </summary>
    public partial class EditTrStudyGain : ListPage
    {
        
        BTrGainShare Btrac = new BTrGainShare();  //实例化业务处理类
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(ZX.WebApp.TR.EditTrStudyGain));
            ReturnString = Review();
        }
        /// <summary>
        /// 点评信息管理
        /// </summary>
        public string ReturnString
        {
            get;
            set;
        }
         /// <summary>
        /// 生成处理界面
        /// </summary>
        /// <returns></returns>
        public string Review()
        {
            string strEntity = this.GetStringFromQueryString("entity", "V_TrActivityCourseX");   //实体类
            string id = this.GetStringFromQueryString("ID", "");        //课程活动的主键  
            DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"]; //用户ID
            string review = string.Empty;
            if (du != null)
            {
                int type = int.Parse(this.GetStringFromQueryString("type", "1"));    //备注 1：做新增心得  2：做编辑心得   3:新增点评  4:编辑点评   5:查看
                if (type == 1)
                {                    
                    #region ==========新增心得============
                    this.txtusername.Value = du.UName;
                    this.txtaddtime.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    Btrac.entity = new V_TrActivityCourseX();
                    V_TrActivityCourseX vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("StudentName like '%" + du.UserID + "%'  and  ExpectationUser='"+ du.UserID.ToString()+"'");
                    if (vActivityCourse == null)
                    {
                        vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("StudentName like '%" + du.UserID + "%'");
                    }
                    if (vActivityCourse != null)
                    {
                        this.txtcoursename.Value = vActivityCourse.CourseName;
                        this.txtcoursestartime.Value = vActivityCourse.InfactStartTime.ToString();                        
                        //this.txtusername.Value = vActivityCourse.UName;
                        //this.txtaddtime.Value = vActivityCourse.AddTime.ToString();
                        this.TxtAreaExpectation.Value = vActivityCourse.Expectation.ToString();
                        this.txtid.Value = vActivityCourse.TrActivityCourseID.ToString();
                    }
                    #endregion
                }
                else if (type == 2)
                {
                    #region ==========编辑心得=========
                    this.Btrac.entity = new  V_TrStudyGain();
                     V_TrStudyGain vStudyGain = (V_TrStudyGain)Btrac.GetEntityById(id);
                     if (vStudyGain != null)
                    {
                        SetControlEval(vStudyGain,vStudyGain.AddUser);
                        IList<V_TrStudyGainCheck> IGainCheck = Btrac.GetVTrStudyGainCheck("TrStudyGainID='" + id + "'");
                        if(IGainCheck !=null)        //心得内容已经点评 不可以修改
                        {
                            
                            for(int i = 0; i < IGainCheck.Count; i++)
                            {
                                string TxtCheckContent= "TxtCheckContent" + i.ToString();
                                review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                       + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                       + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].AddTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                       + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                       + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + " disabled=\"disabled\" class=\"yui-area\" style=\"overflow:hidden ; width: 97%; \" >" + IGainCheck[i].GainContent + "</textarea></td></tr> </table>";
                            }
                            EnableControl(4);
                        }
                        else                      //心得没有点评
                        {
                            //EnableControl(type);
                        }

                    }
                    #endregion
                }
                else if (type == 3)
                {
                    #region =============新增点评================
                    this.Btrac.entity = new V_TrStudyGain();
                    string TxtCheckContent = "TxtCheckContent";
                    V_TrStudyGain vStudyGain = (V_TrStudyGain)Btrac.GetEntityById(id);
                    if (vStudyGain != null)
                    {
                        EnableControl(4);
                        SetControlEval(vStudyGain, vStudyGain.AddUser);
                        IList<V_TrStudyGainCheck> IGainCheck = Btrac.GetVTrStudyGainCheck("TrStudyGainID='" + id + "'");
                        if (IGainCheck != null)        //心得内容已经点评 不可以修改
                        {
                            int j = 0;   //初始化
                            for (int i = 0; i < IGainCheck.Count; i++)
                            {
                                j = i;
                                 TxtCheckContent  +=i.ToString();
                                review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                       + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                       + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].AddTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                       + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                       + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + " disabled=\"disabled\" class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" >" + IGainCheck[i].GainContent + "</textarea></td></tr> </table>";
                            }
                            TxtCheckContent +=(j + 1).ToString();
                            review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                      + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + du.UName+ "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                      + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                      + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                      + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + "  class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" ></textarea></td></tr> </table>";
                            
                        }
                        else                      //心得没有点评
                        {
                            TxtCheckContent += 0.ToString();
                            review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                      + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + du.UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                      + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                      + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                      + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + "  class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" ></textarea></td></tr> </table>";
                       }
                        

                    }
                    txtContent.Value = TxtCheckContent;
                    #endregion
                }
                else if (type == 4)
                {
                    #region ===========编辑点评=============
                    this.Btrac.entity = new V_TrStudyGain();
                    string TxtCheckContent = "TxtCheckContent";
                    V_TrStudyGain vStudyGain = (V_TrStudyGain)Btrac.GetEntityById(id);
                    if (vStudyGain != null)
                    {
                        EnableControl(4);
                        SetControlEval(vStudyGain,vStudyGain.AddUser);
                        IList<V_TrStudyGainCheck> IGainCheck = Btrac.GetVTrStudyGainCheck("TrStudyGainID='" + id + "'");
                        if (IGainCheck != null)        //心得内容已经点评 不可以修改
                        {
                            for (int i = 0; i < IGainCheck.Count; i++)
                            {
                                if (du.UserID.ToString() != IGainCheck[i].AddUser.ToString())
                                {
                                    TxtCheckContent += i.ToString();
                                    review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                           + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                           + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].AddTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                           + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                           + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + " disabled=\"disabled\" class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" >" + IGainCheck[i].GainContent + "</textarea></td></tr> </table>";
                                }
                                else
                                {
                                    TxtCheckContent += i.ToString();
                                    review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                           + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                           + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].AddTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                           + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                           + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + "  class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" >" + IGainCheck[i].GainContent + "</textarea></td></tr> </table>";

                                    txtGainCheckID.Value = IGainCheck[i].TrStudyGainCheckID.ToString();   //获取点评信息的主键
                                }
                            }
                        }
                      
                    }
                    txtContent.Value = TxtCheckContent;
                    #endregion
                }
                else if (type == 5)
                {
                    #region ========查看=========
                    this.Btrac.entity = new V_TrStudyGain();
                    V_TrStudyGain vStudyGain = (V_TrStudyGain)Btrac.GetEntityById(id);
                    if (vStudyGain != null)
                    {
                        SetControlEval(vStudyGain, vStudyGain.AddUser);
                        IList<V_TrStudyGainCheck> IGainCheck = Btrac.GetVTrStudyGainCheck("TrStudyGainID='" + id + "'");
                        if (IGainCheck != null)        //心得内容已经点评 不可以修改
                        {

                            for (int i = 0; i < IGainCheck.Count; i++)
                            {
                                string TxtCheckContent = "TxtCheckContent" + i.ToString();
                                review += "<table   style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%; line-height:20px;\" ><tr><td class=\"style98\">点评人</td><td class=\"style31\">"
                                       + "<input id=\"txtReview\" runat=\"server\" name=\"IssueTitle0\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].UName + "' /></td><td class=\"style98\">点评时间</td><td  class=\"style31\">&nbsp;"
                                       + "<input id=\"txtReviewtime\" runat=\"server\" name=\"IssueTitle1\" type=\"text\"  class=\"style80\" disabled=\"disabled\" value='" + IGainCheck[i].AddTime.ToString("yyyy-MM-dd HH:mm") + "' /></td></tr></table>"
                                       + "<table  style=\"font-weight:normal;  border: solid 1px #D4DBE2; background-color:#F2F8FF; white-space: nowrap; width: 100%;\" ><tr><td class=\"style98\">点评内容</td><td class=\"style50\">"
                                       + "<textarea id=" + TxtCheckContent + "  runat=\"server\" name=" + TxtCheckContent + "  disabled=\"disabled\" class=\"yui-area\" style=\"overflow:hidden; width: 97%;\" >" + IGainCheck[i].GainContent + "</textarea></td></tr> </table>";
                                        }
                            
                        }                       

                    }
                    EnableControl(4);
                    #endregion
                }
            }
            return review;

        }

        /// <summary>
        /// 实例化与控件赋值
        /// </summary>
        /// <param name="vtrac">实体对象</param>
        public void SetControlEval(V_TrStudyGain vtrac,Guid  userid)
        {
            this.txtcoursename.Value = vtrac.CourseName;
            this.txtcoursestartime.Value = vtrac.InfactStartTime.ToString();          ;
            this.txtusername.Value = vtrac.UName;
            this.txtaddtime.Value = vtrac.AddTime.ToString();            
            Btrac.entity = new V_TrActivityCourseX();
            V_TrActivityCourseX vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("StudentName like '%" + userid.ToString() + "%'  and  ExpectationUser='" + userid.ToString() + "' and  TrActivityCourseID='" + vtrac.TrActivityCourseID.ToString() + "");
                    if (vActivityCourse == null)
                    {
                        vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("StudentName like '%" + userid.ToString() + "%'");
                    }
                    if (vActivityCourse != null)
                    {
                        this.TxtAreaExpectation.Value = vActivityCourse.Expectation.ToString();
                    }
          
            this.TxtGain.Value = vtrac.Gain.ToString();
            this.TxtPreResult.Value = vtrac.PreResult.ToString();
            this.TxtMeasure.Value = vtrac.Measure.ToString();
            this.TxtPunish.Value = vtrac.Punish.ToString();
        }

      
           /// <summary>
        /// 控件设置
        /// </summary>
        private void EnableControl(int type)
        {
            this.txtusername.Disabled = true;
            this.txtaddtime.Disabled = true;
            this.txtcoursename.Disabled = true;            
            this.txtcoursestartime.Disabled = true;
            this.btnSelect.Disabled = true;
            if (type == 4)  //设置控件不可编辑
            {
                this.TxtAreaExpectation.Disabled = true;
                this.TxtGain.Disabled = true;
                this.TxtPreResult.Disabled = true;
                this.TxtMeasure.Disabled = true;
                this.TxtPunish.Disabled = true;    
            }
        
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="CourseID">课程ID</param>
        /// <param name="Userid">用户ID</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public  string  SelectExpectation(string CourseID, string Userid)
        {

            string returnstr=string.Empty;
            Btrac.entity = new V_TrActivityCourseX();
            V_TrActivityCourseX vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("TrCourseID = '" + CourseID + "'  and  ExpectationUser='" + Userid.ToString() + "'");
            if (vActivityCourse == null)
            {
                vActivityCourse = (V_TrActivityCourseX)Btrac.GetEntityByCondition("TrCourseID = '" + CourseID + "'and  StudentName LIKE  '%" + Userid.ToString() + "%'");
                if (vActivityCourse == null) {

                    returnstr = "" + "︾" + ""; 
                }
                returnstr = vActivityCourse.TrActivityCourseID.ToString() + "︾" + "";
            }
            if (vActivityCourse != null)
            {
                returnstr = vActivityCourse.TrActivityCourseID.ToString() + "︾" + vActivityCourse.Expectation.ToString();
            }
            return returnstr;
        }

    }
}